<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="java.sql.*"%>
<%@ page import="schronisko.*,Users.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="styles/images.css">
<style type="text/css">
body {
	background: #c6b154;
}
</style>
<title>Ostatnio przygarniete zwierzeta</title>
</head>
<body>
<% 
				//wyswietla zwierzeta przygarniete w ciagu ostatnich 3 miesiecy
				Queries q = new Queries();
				ResultSet r = q.latestAnimals();
				
				if (r != null) {
					out.println("<a href='index.jsp'>Powrot do strony glownej</a><br>");
					out.println("<h1><center>Ostatnio przygarniete</center></h1>");
					String avail = null;
					String plec = null;
					while (r.next()) {
						if(r.getString("gender").equals("male")){
							plec = "M";
						}
						if(r.getString("gender").equals("female")){
							plec= "K";
						}
						if(r.getString("accessibility").equals("available"))
							avail = "DOSTEPNY";
						if(r.getString("accessibility").equals("adopted"))
							avail = "ADOPTOWANY";
							
						if(r.getString("accessibility").equals("pending"))
							avail = "OCZEKUJACY";
						if(r.getString("accessibility").equals("dead"))
							avail = "MARTWY";
						int ID = r.getInt(1);
						String picture = r.getString("pic");
						int dlugosc = picture.length();
						session.setAttribute("ID_animal", ID);
						out.println("<div class='image'><div class='main'>"
								+ "Imie: " + r.getString("name") + "<br>"
								+ "Rasa: "+r.getString("race") + "<br>"
								+ "Plec: " + plec + "<br>"
								+ "Data urodzenia: "+ r.getString("date_of_birth") +"<br>"
								+ "Ostatnie szczepienie: "+ r.getString("last_inoculation") +"<br>"
								+ avail + "<br><br>");
						if(avail.equals("DOSTEPNY")){
							String username = null;
							try{
							username = (String)session.getAttribute("username");
							}
							catch(NullPointerException e){
								
							}
							if(username != null){
						out.println("<form action='AdoptAnimal' method='post'>"
								+ "<input id='id' name='id' type='hidden' value=" + ID + ">"
								+ "<input type='submit' value='Adoptuj'></form>" + "<br>");
							}
							else{
								out.println("<form action='Register.jsp' method='post'>"
										+ "<input id='id' name='id' type='hidden' value=" + ID + ">"
										+ "<input type='submit' value='Zaloguj sie, aby moc zaadoptowac tego zwierzaka'></form>" + "<br>");
							}
						}
						out.println("</div><img src='" + picture.substring(3, dlugosc) +"'>"
								+ "<div class='details'>Informacje dodatkowe: <br>"
								+ r.getString("description")+
								"</div></div><br><br><br><br><br><br><br><br><br><br><br><br><br>");
						
					}
				}
				else {
					out.println("Problem z baza danych<br>Prosimy sprobowac pozniej");
				}
				MySQLConnection.Close();
					
%>
</body>
</html>